package vip.xiaonuo.biz.modular.file.provider;

import cn.hutool.json.JSONObject;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import vip.xiaonuo.biz.api.BizFileManagerApi;
import vip.xiaonuo.biz.modular.file.entity.BizFile;
import vip.xiaonuo.biz.modular.file.entity.BizFileManager;
import vip.xiaonuo.biz.modular.file.service.BizFileManagerService;
import vip.xiaonuo.dev.api.DevFileApi;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author xsl
 * @date 2024-08-20 21:11
 **/
@Service
public class BizFileApiProvider implements BizFileManagerApi {

    @Resource
    private BizFileManagerService bizFileManagerService;

    @Resource
    private DevFileApi devFileApi;

    @Override
    public List<JSONObject> getByFileIdList(List<String> idList) {
        List<JSONObject> res =  new ArrayList<>();
        for(String id : idList){
            res.add( new JSONObject(bizFileManagerService.getByFileId(id)));
        }
        return res;
    }

    @Override
    public JSONObject getByFileId(String id) {
        return new JSONObject(bizFileManagerService.getByFileId(id));
    }

    @Override
    public void updateFile(String fileId, String refId, String motionId, String fileType) {
       BizFileManager bizFileManager = bizFileManagerService.getByFileId(fileId);
       bizFileManager.setRefId(refId);
       bizFileManager.setFileType(fileType);
       bizFileManager.setMotionId(motionId);
       bizFileManagerService.updateById(bizFileManager);
    }

    public void updateFile(String fileId, String refId,  String fileType) {
        BizFileManager bizFileManager = bizFileManagerService.getByFileId(fileId);
        bizFileManager.setRefId(refId);
        bizFileManager.setFileType(fileType);
        bizFileManagerService.updateById(bizFileManager);
    }

    @Override
    public String getFileUrl(String id) {
        return bizFileManagerService.getFileUrl(id);
    }
}
